/**
 * comment-index.js
 * 
 * Interaction for comment interface
 * 
 * @todo This should be able to reload both columns with just one HTTP request
 * @todo The /ajax/1 parameter that is appended to the URL could be used on the server site to trim down on processing
 * @todo A nicer loading message could be displayed
 * @todo Animate the moving of comments rather than just reloading the columns
 */

$(document).ready(function(){
	
	//Use event bubbling to capture the onclick event.
	//Good explanation here: http://docs.jquery.com/Tutorials:AJAX_and_Events
	$('.spam-col').add('.recent-col').click(function(event) {
		
		var t = $(event.target);
		if (	t.is('a.accept') || 
				t.is('a.reject')){ 
			reloadSpamCol(t.attr('href'));
			reloadRecentCol(t.attr('href'));
			event.preventDefault();
		}
	});
	
});

function reloadSpamCol(url) {
	//Stop these requests being cached (otherwise nothing will happen!)
	var cacheBuster = '/cb/' + Math.floor(Math.random() * 10000000);
	$('.spam-col div.post-comments').load(url + cacheBuster + '/ajax/1 .spam-col .post-comments', {}, function(responseText, textStatus, XMLHttpRequest) {
		
	}).html('Please wait, loading...');
}

function reloadRecentCol(url) {
	//Stop these requests being cached (otherwise nothing will happen!)
	var cacheBuster = '/cb/' + Math.floor(Math.random() * 10000000);
	$('.recent-col div.post-comments').load(url + cacheBuster + '/ajax/1 .recent-col .post-comments', {}, function(responseText, textStatus, XMLHttpRequest) {
		
	}).html('Please wait, loading...');
}

